<?php
// vim:set expandtab tabstop=3 shiftwidth=3 softtabstop=3 foldclose=all foldmethod=marker:
/**
 * 项目：   5anet
 * 文件：   class/calendar/ShowAdd.class.php
 *
 * 显示新增日历的界面
 *
 * PHP Version 5
 *
 * @package:   class.calendar
 * @author:    Mike.G Chinese Name: 黄叶 <hylinux@gmail.com>
 * @license:   http://www.gnu.org/copyleft/lesser.html  LGPL License 2.1 
 * @copyright: www.5anet.com
 * @version:   $Id: $
 * @date:      $Date: $
 */

include_once CLASS_PATH.'main/BaseAction.class.php';

include_once CLASS_PATH.'calendar/CalendarUtil.class.php';

include_once LIB_PATH.'fckeditor/fckeditor.php';

class ShowAdd extends BaseAction {

   /**
    * 数据库的连接
    */
   private $db;


   /**
    * 构造函数
    * @param:  NULL
    * @return: NULL
    * @access: public
    */
   public function __construct() {
      $this->db = $this->getDB();
   }

   /**
    * 显示新增日历的界面
    * @param:  NULL
    * @return: NULL
    * @access: public
    */
   public function run() {

      $type = $this->getParameter('type');

      $now = getdate();

      $now_year = $now['year'];
      $now_month = $now['mon'];
      $now_day = $now['mday'];

      //取得日期的参数
      $year = $this->getParameter('year');

      if ( !$year ) {
         $year = $now_year;
      }

      $month = $this->getParameter('mon');
      if ( !$month ) {
         $month = $now_month;
      }

      $day = $this->getParameter('day');
      if ( !$day ) {
         $day = $now_day;
      }

      //如果提供的日期不合法，则采用现在的日期

      if ( !checkdate($month, $day, $year) ) {
         $year = $now_year;
         $month = $now_month;
         $day = $now_day;
      }


      //生成日历

      $total_day = 0;

      if ( $month == 1 ||
            $month == 3 ||
            $month == 5 ||
            $month == 7 ||
            $month == 8 ||
            $month == 10 ||
            $month == 12  ) {
               $total_day = 31;
      } else if ( $month == 2 ) {
         if ( checkdate(2, 29, $year) ) {
            $total_day = 29;
         } else {
            $total_day = 28;
         }
      } else {
         $total_day = 30;
      }


      $smarty = $this->getSmarty();

      $fck = new FCKeditor("content");
      $fck->BasePath = FCKEDITOR_BASEPATH;
       $fck->ToolbarSet = 'Basic';
     

      $smarty->assign('fck', $fck);

      //设置SEO的头
      $smarty->assign('clone_title', '新增日历事件/5anet.com' );
      $smarty->assign('header_meta_content','新增日历事件/5anet.com' );


      //生成年份和月份的选择框
      $year_option = "";

      for($i=2005; $i<2015; $i++ ) {
         $year_option .= "<option value=$i ";
         if ( $i == $year ) {
            $year_option .= " selected ";
         }
         $year_option .= ">".$i."</option>\n";
      }

      $smarty->assign('year_option', $year_option);


      //生成月份的选择框
      $month_option = "";
      for ( $i=1; $i<=12; $i++ ) {
         $month_option .= "<option value=$i ";

         if ( $i == $month ) {
            $month_option .= " selected ";
         }

         $month_option .= ">".$i."</option>\n";
      }

      $smarty->assign('month_option', $month_option);

      //生成日的选择框

      $day_option = "";

      for ( $i=1; $i<=$total_day; $i++ ) {
         $day_option .= "<option value=$i ";

         if ( $i == $day ) {
            $day_option .= " selected ";
         }

         $day_option .= ">".$i."</option>\n";
      }

      $smarty->assign('day_option', $day_option);

      $smarty->assign('type', $type);



      $smarty->display('showaddcalendar.tmpl');





   }



}




?>
